﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <script src="Scripts/jquery-1.8.3.js" type="text/javascript"></script>
    <script src="http://api.map.baidu.com/api?v=1.4" type="text/javascript"></script>
    <!--加载鼠标绘制工具-->
<script type="text/javascript" src="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.js"></script>
<link rel="stylesheet" href="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.css" />
<!--加载检索信息窗口-->
<script type="text/javascript" src="http://api.map.baidu.com/library/SearchInfoWindow/1.4/src/SearchInfoWindow_min.js"></script>
<link rel="stylesheet" href="http://api.map.baidu.com/library/SearchInfoWindow/1.4/src/SearchInfoWindow_min.css" />

    <style type="text/css">
        
        html
        {
            height:100%;
        }
        body
        {
            height:100%;
            margin:20px;
            padding:20px;
            
        }
        #container
        {
            width: 90%;
            height:90%;
        }
        
        </style>
        <script type="text/javascript">



        </script>
</head>
<body>
<div id="container"></div>
</body>
</html>

<script type="text/javascript">
    var map = new BMap.Map("container");          // 创建地图实例
    var point = new BMap.Point(116.364187, 40.047909);  // 创建点坐标
    map.centerAndZoom(point, 13);                 // 初始化地图，设置中心点坐标和地图级别
    //window.setTimeout(function () { map.panTo(new BMap.Point(116.409, 39.918)); }, 2000);
    map.addControl(new BMap.NavigationControl());

   // var opts = { offset: new BMap.Size(150, 5) }
    map.addControl(new BMap.ScaleControl());

    map.addControl(new BMap.OverviewMapControl());
    map.addControl(new BMap.MapTypeControl());
    //map.setCurrentCity("北京"); // 仅当设置城市信息时，MapTypeControl的切换功能才能可用

//    var myDrawingManagerObject = new BMapLib.DrawingManager(map, { isOpen: true,
//        //drawingType: BMAP_DRAWING_MARKER, 
//        enableDrawingTool: true,
//        enableCalculate: false,
//        drawingToolOptions: {
//            anchor: BMAP_ANCHOR_TOP_LEFT,
//            offset: new BMap.Size(80, 0),
//            drawingTypes: [
//                BMAP_DRAWING_MARKER,
//                BMAP_DRAWING_CIRCLE,
//                BMAP_DRAWING_POLYLINE,
//                BMAP_DRAWING_POLYGON,
//                BMAP_DRAWING_RECTANGLE
//             ]
//        },
//        polylineOptions: {
//            strokeColor: "red"
//        }
//    });

//    map.addEventListener("click", function (e) {
//        alert(e.point.lng + "," + e.point.lat);
//    });


    var conpanyPoint = new BMap.Point(116.489438, 39.992571);

    //创建公司点
    //var pt = new BMap.Point(116.417, 39.909);
        var myIcon = new BMap.Icon("Img/sony.png", new BMap.Size(90, 30));
        var marker2 = new BMap.Marker(conpanyPoint, { icon: myIcon });  // 创建标注
    map.addOverlay(marker2);              // 将标注添加到地图中


    $(document).ready(function () {

        $.ajax({
            type: "GET",
            url: "shuttleBusRoute.json",
            success: function (data) {
                var json = eval('(' + data + ')');
                var busLines = json.BusLines;

                var stopPoints = [];

                for (var i = 0; i < busLines[0].comeStops.length; i++) {
                    //alert(busLines[0].comeStops[i].stopLNG + ' - ' + busLines[0].comeStops[i].stopLAT);

                    var stopPoint = new BMap.Point(busLines[0].comeStops[i].stopLNG, busLines[0].comeStops[i].stopLAT);

                    var marker1 = new BMap.Marker(stopPoint);  // 创建标注
                    map.addOverlay(marker1);              // 将标注添加到地图中

                    //创建信息窗口
                    var infoWindow1 = new BMap.InfoWindow("车号：" + busLines[0].busID + "<br />终点站：" + busLines[0].terminus + "<br />司机：" + busLines[0].motorman + "<br /><b>站号：" + busLines[0].comeStops[i].stopNum + "</b><br /><b>站名：" + busLines[0].comeStops[i].stopName);
                    marker1.win = infoWindow1;
                    marker1.addEventListener("click", function () { this.openInfoWindow(this.win); });

                    stopPoints.push(stopPoint);
                }
                stopPoints.push(conpanyPoint);
                var polyline = new BMap.Polyline(stopPoints,
                        { strokeColor: "blue", strnokeWeight: 6, strokeOpacity: 0.5 }
                    );
                map.addOverlay(polyline);

//                for (var i = 0; i < stopPoints.length; i++) {
//                    if (i == 0) {
//                        continue;
//                    }
//                    var prePoint = stopPoints[i - 1];
//                    var thisPoint = stopPoints[i];

//                    var driving = new BMap.DrivingRoute(map, { renderOptions: { map: map, autoViewport: false} });
//                    driving.search(prePoint, thisPoint);
                   
//                }
            },
            error: function (data) {
                alert('error:' + s);
            }
        })
    });


</script>


